package cn.itcast.demo01.utils;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.util.ResourceBundle;

public class JedisUtil {

    private static JedisPoolConfig poolConfig=null;
    private static JedisPool jedisPool=null;
    private static int maxTotal=0;
    private static int maxIdel=0;
    private static String host=null;
    private static int port=0;


    static{
        ResourceBundle bundle=ResourceBundle.getBundle("jedis");
        host=bundle.getString("jedis.host");
        port=Integer.parseInt(bundle.getString("jedis.port"));
        maxTotal=Integer.parseInt(bundle.getString("jedis.maxTotal"));
        maxIdel=Integer.parseInt(bundle.getString("jedis.maxIdle"));

        poolConfig=new JedisPoolConfig();
        poolConfig.setMaxTotal(maxTotal);
        poolConfig.setMaxIdle(maxIdel);
        jedisPool=new JedisPool(poolConfig,host,port);

    }

    public static Jedis getJedis(){
        return jedisPool.getResource();
    }




}
